function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["text", "onResult", "children"],
  _excluded2 = ["buttonMode", "acceptInput", "nowrap", "input", "modal", "multiple", "tooltip", "disabled", "helpContent", "valueField", "labelField", "getHelpInfo", "userCodeFieldWithLabel", "userCodeField", "outRef", "onBeforeOpen", "placeholder", "onChange", "modalProps", "selectedRequest", "data", "request", "contentParams", "id", "loadByFocus", "style", "onDoubleClick", "onDropdownVisibleChange", "onOpenChange", "allowSelectedEmpty", "isTree"],
  _excluded3 = ["type", "closeReturn"];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
import { LoadingOutlined, SearchOutlined } from '@ant-design/icons';
import { ConfigProvider, Empty, Pagination, Spin, Tooltip } from 'antd';
import zhCN from 'antd/lib/locale/zh_CN';
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { createRoot } from 'react-dom/client';
import { Select } from "../../baseComponent";
import { message } from "../antd/message";
import { getGlobalConfig, getRegisterComponentWithProps, iup, Observer, useIUPEffect, useRefCallback } from "../../util";
import { Button } from "../antd/Button";
import { showModal } from "../modal";
import { BaseContent, Footer, Header, HelpContext, MultipleButtons } from "./baseContent";
import "./index.less";
import { helpLocale } from "./locale";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var timeout;
var iconStyle = {
  zIndex: 2,
  fontSize: 12,
  display: 'flex'
};

/**
 * 请求节流、返回值处理
 * @param request 请求
 * @param callback 回调
 * @param delay 延时
 */
function fetch(request, callback) {
  var delay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  var asyncFn = /*#__PURE__*/function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
      var _ref2, _result$record, _ref3, _result$total;
      var result;
      return _regeneratorRuntime().wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return request();
          case 2:
            result = _context.sent;
            callback((_ref2 = (_result$record = result.record) !== null && _result$record !== void 0 ? _result$record : result.list) !== null && _ref2 !== void 0 ? _ref2 : [], (_ref3 = (_result$total = result.total) !== null && _result$total !== void 0 ? _result$total : result.totalRows) !== null && _ref3 !== void 0 ? _ref3 : 0);
          case 4:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function asyncFn() {
      return _ref.apply(this, arguments);
    };
  }();
  if (delay > 0) {
    if (timeout) {
      clearTimeout(timeout);
      timeout = null;
    }
    timeout = setTimeout(asyncFn, delay);
  } else {
    asyncFn().then(function () {});
  }
}

/**
 * 弹出窗工厂
 * @param request 请求相关信息 { valueField, labelField, request}
 * @param HelpContent 自定义内容组件
 * @param helpRef 弹出modal对象
 */
function contentFactory(request, HelpContent, helpRef) {
  var _helpRef$current, _helpRef$current2;
  var tmpParams = ((_helpRef$current = helpRef.current) === null || _helpRef$current === void 0 ? void 0 : _helpRef$current.contentParams) || {};
  var defaultColumns = [{
    dataIndex: iup.isFunction(tmpParams.valueField) ? 'code' : tmpParams.valueField,
    title: helpLocale.code
  }, {
    dataIndex: iup.isFunction(tmpParams.labelField) ? 'name' : tmpParams.labelField,
    title: helpLocale.name
  }];
  var providerValue = {
    observer: (_helpRef$current2 = helpRef.current) === null || _helpRef$current2 === void 0 ? void 0 : _helpRef$current2.observer,
    close: function () {
      var _close = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
        var _tmpParams$onCancel, _helpRef$current3;
        var valid;
        return _regeneratorRuntime().wrap(function _callee2$(_context2) {
          while (1) switch (_context2.prev = _context2.next) {
            case 0:
              _context2.next = 2;
              return (_tmpParams$onCancel = tmpParams.onCancel) === null || _tmpParams$onCancel === void 0 ? void 0 : _tmpParams$onCancel.call(tmpParams);
            case 2:
              valid = _context2.sent;
              if (!(valid === false)) {
                _context2.next = 5;
                break;
              }
              return _context2.abrupt("return");
            case 5:
              return _context2.abrupt("return", (_helpRef$current3 = helpRef.current) === null || _helpRef$current3 === void 0 ? void 0 : _helpRef$current3.close('cancel', null));
            case 6:
            case "end":
              return _context2.stop();
          }
        }, _callee2);
      }));
      function close() {
        return _close.apply(this, arguments);
      }
      return close;
    }(),
    ok: function () {
      var _ok = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(result) {
        var _tmpParams$onOk;
        var valid, _helpRef$current4, emptyValue, _helpRef$current5;
        return _regeneratorRuntime().wrap(function _callee3$(_context3) {
          while (1) switch (_context3.prev = _context3.next) {
            case 0:
              _context3.next = 2;
              return (_tmpParams$onOk = tmpParams.onOk) === null || _tmpParams$onOk === void 0 ? void 0 : _tmpParams$onOk.call(tmpParams, result);
            case 2:
              valid = _context3.sent;
              if (!(valid === false)) {
                _context3.next = 5;
                break;
              }
              return _context3.abrupt("return");
            case 5:
              if (!(result === void 0 && tmpParams.allowSelectedEmpty)) {
                _context3.next = 9;
                break;
              }
              emptyValue = tmpParams.multiple ? [] : result;
              helpRef.current.setValue(emptyValue);
              return _context3.abrupt("return", (_helpRef$current4 = helpRef.current) === null || _helpRef$current4 === void 0 ? void 0 : _helpRef$current4.close('ok', emptyValue));
            case 9:
              if (!(iup.isObject(result) || iup.isArray(result))) {
                _context3.next = 14;
                break;
              }
              helpRef.current.setValue(result);
              return _context3.abrupt("return", (_helpRef$current5 = helpRef.current) === null || _helpRef$current5 === void 0 ? void 0 : _helpRef$current5.close('ok', result));
            case 14:
              // 返回false表示自定义提示方式，这里不需要额外处理
              if (result !== false) {
                message.warning({
                  content: result || helpLocale.noSelected,
                  key: 'help_message_key'
                });
              }
            case 15:
            case "end":
              return _context3.stop();
          }
        }, _callee3);
      }));
      function ok(_x) {
        return _ok.apply(this, arguments);
      }
      return ok;
    }(),
    contentParams: _objectSpread({
      FilterTree: null,
      columns: defaultColumns,
      getFieldValue: function getFieldValue(r) {
        var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'value';
        var field = type === 'label' ? tmpParams.labelField : tmpParams.valueField;
        if (iup.isFunction(field)) {
          return field(r);
        }
        if (!r.hasOwnProperty(field)) {
          iup.debug({
            msg: "\u5F53\u524D\u914D\u7F6E\u7684 ".concat(type, "Field \u4E3A ").concat(field, "\uFF0C\u6570\u636E\u6E90\u4E2D\u672A\u5339\u914D\u5230\u8BE5\u5C5E\u6027\uFF01"),
            type: 'error'
          });
        }
        return r[field];
      }
    }, tmpParams),
    request: request,
    locale: helpLocale,
    randomKey: Math.random().toString(32).slice(2)
  };
  return /*#__PURE__*/_jsx(ConfigProvider, {
    locale: zhCN,
    children: /*#__PURE__*/_jsx(HelpContext.Provider, {
      value: providerValue,
      children: HelpContent ? iup.isReactElement(HelpContent) ? HelpContent : /*#__PURE__*/_jsx(HelpContent, {}) : /*#__PURE__*/_jsx(BaseContent, {})
    })
  });
}

/**
 * 初始化state状态
 */
function initState(_ref4) {
  var request = _ref4.request,
    data = _ref4.data;
  return {
    options: request ? [] : data || [],
    total: 0,
    loading: false,
    firstLoad: true,
    query: {
      keyword: '',
      pageIndex: 1,
      pageSize: 8
    }
  };
}

/**
 * 下拉面板
 * @param menu 选择项
 * @param pageChange 页码事件
 * @param state 父组件的状态
 * @constructor
 */
function DropdownRender(_ref5) {
  var menu = _ref5.menu,
    pageChange = _ref5.pageChange,
    state = _ref5.state;
  return /*#__PURE__*/_jsxs(Spin, {
    spinning: state.loading,
    size: "small",
    children: [/*#__PURE__*/_jsx("div", {
      children: menu
    }), state.total > state.options.length && /*#__PURE__*/_jsx(Pagination, {
      size: "small",
      total: state.total,
      current: state.query.pageIndex,
      style: {
        display: 'flex',
        flexWrap: 'nowrap',
        whiteSpace: 'nowrap',
        padding: '5px 12px',
        borderTop: '1px solid #f5f5f5'
      },
      showSizeChanger: false,
      hideOnSinglePage: true,
      showQuickJumper: true,
      showLessItems: true,
      showTotal: function showTotal(totalCount) {
        return "\u5171".concat(totalCount, "\u6761");
      },
      onChange: pageChange,
      pageSize: state.query.pageSize
    })]
  });
}

/**
 * 打开弹窗组件
 * @param request 请求相关信息
 * @param outRef 暴露外部api
 * @param helpContent 自定义弹出窗口内容
 * @param modalProps modal的属性
 * @param selectedRequest 已选数据接口
 * @param onBeforeOpen 打开前的钩子函数，获取帮助的基本信息
 * @param style 图标样式
 * @param contentParams 组件传递过来的额外属性
 * @param buttonMode 按钮模式
 * @constructor
 */
function OpenHelpIcon(_ref6) {
  var request = _ref6.request,
    outRef = _ref6.outRef,
    helpContent = _ref6.helpContent,
    modalProps = _ref6.modalProps,
    selectedRequest = _ref6.selectedRequest,
    onBeforeOpen = _ref6.onBeforeOpen,
    style = _ref6.style,
    contentParams = _ref6.contentParams,
    buttonMode = _ref6.buttonMode;
  var helpId = contentParams === null || contentParams === void 0 ? void 0 : contentParams.helpId;
  var helpRef = useRef({
    observer: new Observer(),
    contentParams: contentParams,
    helpInfo: null,
    modalInstance: null,
    setValue: function setValue(value) {
      var _outRef$current, _outRef$current$getAp, _outRef$current$getAp2;
      return (_outRef$current = outRef.current) === null || _outRef$current === void 0 || (_outRef$current$getAp = _outRef$current.getApi) === null || _outRef$current$getAp === void 0 || (_outRef$current$getAp = _outRef$current$getAp.call(_outRef$current)) === null || _outRef$current$getAp === void 0 || (_outRef$current$getAp2 = _outRef$current$getAp.setValue) === null || _outRef$current$getAp2 === void 0 ? void 0 : _outRef$current$getAp2.call(_outRef$current$getAp, value);
    },
    close: function close() {
      var _helpRef$current6;
      var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'cancel';
      var result = arguments.length > 1 ? arguments[1] : undefined;
      if ((_helpRef$current6 = helpRef.current) !== null && _helpRef$current6 !== void 0 && _helpRef$current6.modalInstance) {
        helpRef.current.afterCloseParams = {
          type: type,
          helpId: helpId,
          result: result
        };
        helpRef.current.modalInstance.destroy();
        helpRef.current.modalInstance = null;
        if (type === 'cancel') {
          var _modalProps$onCancel;
          modalProps === null || modalProps === void 0 || (_modalProps$onCancel = modalProps.onCancel) === null || _modalProps$onCancel === void 0 || _modalProps$onCancel.call(modalProps);
        }
      }
    }
  });
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    loading = _useState2[0],
    setLoading = _useState2[1];
  var showModalEx = /*#__PURE__*/function () {
    var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
      var _outRef$current$getAp3, _outRef$current2, _outRef$current$getAp4, _helpRef$current$help;
      var _outRef$current$getAp5, _outRef$current$getAp6, _contentParams$value, origin, _getGlobalConfig$defa, width, height;
      return _regeneratorRuntime().wrap(function _callee4$(_context4) {
        while (1) switch (_context4.prev = _context4.next) {
          case 0:
            setLoading(true);
            if (!onBeforeOpen) {
              _context4.next = 10;
              break;
            }
            _context4.next = 4;
            return onBeforeOpen();
          case 4:
            helpRef.current.helpInfo = _context4.sent;
            setLoading(false);
            if (!(helpRef.current.helpInfo === false)) {
              _context4.next = 8;
              break;
            }
            return _context4.abrupt("return");
          case 8:
            _context4.next = 11;
            break;
          case 10:
            setLoading(false);
          case 11:
            contentParams.value = (_outRef$current$getAp3 = (_outRef$current2 = outRef.current).getApi) === null || _outRef$current$getAp3 === void 0 || (_outRef$current$getAp3 = _outRef$current$getAp3.call(_outRef$current2)) === null || _outRef$current$getAp3 === void 0 || (_outRef$current$getAp4 = _outRef$current$getAp3.getValue) === null || _outRef$current$getAp4 === void 0 ? void 0 : _outRef$current$getAp4.call(_outRef$current$getAp3);
            if (!contentParams.multiple) {
              _context4.next = 33;
              break;
            }
            origin = (_outRef$current$getAp5 = outRef.current.getApi()) === null || _outRef$current$getAp5 === void 0 || (_outRef$current$getAp6 = _outRef$current$getAp5.getOrigin) === null || _outRef$current$getAp6 === void 0 ? void 0 : _outRef$current$getAp6.call(_outRef$current$getAp5);
            if (!(origin !== null && origin !== void 0 && origin.length)) {
              _context4.next = 18;
              break;
            }
            contentParams.selectedArray = origin;
            _context4.next = 31;
            break;
          case 18:
            if (!((_contentParams$value = contentParams.value) !== null && _contentParams$value !== void 0 && _contentParams$value.length && iup.isFunction(selectedRequest))) {
              _context4.next = 30;
              break;
            }
            _context4.prev = 19;
            _context4.next = 22;
            return selectedRequest({
              codes: contentParams.value.join()
            });
          case 22:
            contentParams.selectedArray = _context4.sent;
            _context4.next = 28;
            break;
          case 25:
            _context4.prev = 25;
            _context4.t0 = _context4["catch"](19);
            contentParams.selectedArray = [];
          case 28:
            _context4.next = 31;
            break;
          case 30:
            contentParams.selectedArray = [];
          case 31:
            _context4.next = 34;
            break;
          case 33:
            contentParams.selectedArray = undefined;
          case 34:
            helpRef.current.contentParams = _objectSpread(_objectSpread({}, contentParams), helpRef.current.helpInfo);
            _getGlobalConfig$defa = getGlobalConfig().default.helpConfig, width = _getGlobalConfig$defa.width, height = _getGlobalConfig$defa.height;
            helpRef.current.modalInstance = showModal(_objectSpread(_objectSpread({
              width: width,
              height: height
            }, modalProps), {}, {
              className: 'help-container',
              icon: null,
              footer: false,
              content: contentFactory(((_helpRef$current$help = helpRef.current.helpInfo) === null || _helpRef$current$help === void 0 ? void 0 : _helpRef$current$help.request) || request, helpContent, helpRef),
              afterClose: function afterClose() {
                var _buttonMode$onResult, _modalProps$afterClos;
                buttonMode === null || buttonMode === void 0 || (_buttonMode$onResult = buttonMode.onResult) === null || _buttonMode$onResult === void 0 || _buttonMode$onResult.call(buttonMode, helpRef.current.afterCloseParams);
                helpRef.current.observer.notify(helpRef.current.afterCloseParams, 'afterClose').then();
                helpRef.current.afterCloseParams = null;
                modalProps === null || modalProps === void 0 || (_modalProps$afterClos = modalProps.afterClose) === null || _modalProps$afterClos === void 0 || _modalProps$afterClos.call(modalProps);
              }
            }));
            helpRef.current.modalInstance.subscribe(function () {
              helpRef.current.observer.notify(helpRef.current.afterCloseParams, 'beforeDestroy').then();
            }, 'beforeDestroy');
            _context4.next = 40;
            return helpRef.current.observer.notify({
              helpId: helpId
            }, 'afterOpen');
          case 40:
          case "end":
            return _context4.stop();
        }
      }, _callee4, null, [[19, 25]]);
    }));
    return function showModalEx() {
      return _ref7.apply(this, arguments);
    };
  }();
  var open = /*#__PURE__*/function () {
    var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(e) {
      return _regeneratorRuntime().wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            if (!loading) {
              _context5.next = 2;
              break;
            }
            return _context5.abrupt("return");
          case 2:
            iup.stopPropagation(e);
            if (helpRef.current.modalInstance) {
              _context5.next = 6;
              break;
            }
            _context5.next = 6;
            return showModalEx();
          case 6:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    }));
    return function open(_x2) {
      return _ref8.apply(this, arguments);
    };
  }();
  useIUPEffect(function () {
    var _helpRef$current7;
    helpRef.current.helpInfo = null;
    (_helpRef$current7 = helpRef.current) === null || _helpRef$current7 === void 0 || _helpRef$current7.close('cancel');
  }, [onBeforeOpen, request, helpId], false);
  useIUPEffect(function () {
    outRef.current.openHelp = open;
    outRef.current.closeHelp = function () {
      var _helpRef$current8;
      (_helpRef$current8 = helpRef.current) === null || _helpRef$current8 === void 0 || _helpRef$current8.close('cancel', null);
    };
    outRef.current.getHelper = function () {
      return helpRef.current;
    };
  });
  if (buttonMode) {
    var text = buttonMode.text,
      onResult = buttonMode.onResult,
      children = buttonMode.children,
      btnProps = _objectWithoutProperties(buttonMode, _excluded);
    return /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
      onClick: open
    }, btnProps), {}, {
      children: text || children
    }));
  }
  return /*#__PURE__*/_jsx("span", {
    style: style,
    children: loading ? /*#__PURE__*/_jsx(LoadingOutlined, {}) : /*#__PURE__*/_jsx(SearchOutlined, {
      onClick: open
    })
  });
}

/**
 * 通用帮助基础组件
 * @param props 属性
 * @constructor
 */
export var BaseHelp = function BaseHelp(props) {
  var buttonMode = props.buttonMode,
    _props$acceptInput = props.acceptInput,
    acceptInput = _props$acceptInput === void 0 ? false : _props$acceptInput,
    _props$nowrap = props.nowrap,
    nowrap = _props$nowrap === void 0 ? false : _props$nowrap,
    _props$input = props.input,
    input = _props$input === void 0 ? true : _props$input,
    _props$modal = props.modal,
    modal = _props$modal === void 0 ? false : _props$modal,
    _props$multiple = props.multiple,
    multiple = _props$multiple === void 0 ? false : _props$multiple,
    tooltip = props.tooltip,
    _props$disabled = props.disabled,
    disabled = _props$disabled === void 0 ? false : _props$disabled,
    _props$helpContent = props.helpContent,
    helpContent = _props$helpContent === void 0 ? null : _props$helpContent,
    valueField = props.valueField,
    labelField = props.labelField,
    getHelpInfo = props.getHelpInfo,
    _props$userCodeFieldW = props.userCodeFieldWithLabel,
    userCodeFieldWithLabel = _props$userCodeFieldW === void 0 ? true : _props$userCodeFieldW,
    defaultUserCodeField = props.userCodeField,
    outRef = props.outRef,
    onBeforeOpen = props.onBeforeOpen,
    placeholder = props.placeholder,
    _onChange = props.onChange,
    modalProps = props.modalProps,
    selectedRequest = props.selectedRequest,
    data = props.data,
    request = props.request,
    contentParams = props.contentParams,
    id = props.id,
    loadByFocus = props.loadByFocus,
    style = props.style,
    onDoubleClick = props.onDoubleClick,
    _onDropdownVisibleChange = props.onDropdownVisibleChange,
    onOpenChange = props.onOpenChange,
    allowSelectedEmpty = props.allowSelectedEmpty,
    isTree = props.isTree,
    others = _objectWithoutProperties(props, _excluded2);
  var getValue = function getValue(r) {
    var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'value';
    var _valueField$labelFiel = _objectSpread({
        valueField: valueField,
        labelField: labelField
      }, getHelpInfo === null || getHelpInfo === void 0 ? void 0 : getHelpInfo()),
      vf = _valueField$labelFiel.valueField,
      lf = _valueField$labelFiel.labelField;
    var v = type === 'label' ? lf : vf;
    return iup.isFunction(v) ? v(r) : r[v || 'code'];
  };
  var innerRef = useRef({
    lockOpen: false,
    open: others.open,
    tmpOpen: undefined,
    lastInput: '',
    focus: false,
    loaded: false
  });
  var ref = useMemo(function () {
    return outRef !== null && outRef !== void 0 ? outRef : /*#__PURE__*/React.createRef();
  }, [outRef]);
  var _useState3 = useState(initState(props)),
    _useState4 = _slicedToArray(_useState3, 2),
    state = _useState4[0],
    setState = _useState4[1];
  var dataRequest = useMemo(function () {
    var req = request ? request : data ? function (_ref9) {
      var keyword = _ref9.keyword;
      return keyword ? data.filter(function (d) {
        return (getValue(d) + '').indexOf(keyword) > -1 || (getValue(d, 'label') + '').indexOf(keyword) > -1;
      }) : data;
    } : function () {
      return [];
    };
    state.options = []; // 很关键，同步清除上一次的状态，减少多余的渲染

    return /*#__PURE__*/function () {
      var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(query) {
        var result;
        return _regeneratorRuntime().wrap(function _callee6$(_context6) {
          while (1) switch (_context6.prev = _context6.next) {
            case 0:
              _context6.next = 2;
              return req(query);
            case 2:
              result = _context6.sent;
              if (!iup.isArray(result)) {
                _context6.next = 7;
                break;
              }
              return _context6.abrupt("return", {
                total: result.length,
                record: result
              });
            case 7:
              if (!iup.isObject(result)) {
                _context6.next = 11;
                break;
              }
              return _context6.abrupt("return", result);
            case 11:
              return _context6.abrupt("return", {
                total: 0,
                record: []
              });
            case 12:
            case "end":
              return _context6.stop();
          }
        }, _callee6);
      }));
      return function (_x3) {
        return _ref10.apply(this, arguments);
      };
    }();
  }, [data, request]);
  useLayoutEffect(function () {
    if (!buttonMode) {
      // 提供关键字检索外部接口，有些业务场景只有名称，需要通过名称去反向检索编码
      ref.current.searchKeyWord = function (params) {
        return dataRequest(_objectSpread({
          pageSize: 8,
          pageIndex: 1
        }, params));
      };
      setState(initState(props));
    }
  }, [dataRequest]);
  var openChangeCallback = useRefCallback(function (open) {
    var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'modal';
    onOpenChange === null || onOpenChange === void 0 || onOpenChange(open, type);
  });
  useEffect(function () {
    var _ref$current;
    if ((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.getHelper) {
      var un1 = ref.current.getHelper().observer.subscribe(function () {
        innerRef.current.lockOpen = true;
        openChangeCallback(true);
      }, 'afterOpen');
      var un2 = ref.current.getHelper().observer.subscribe(function () {
        innerRef.current.lockOpen = false;
        openChangeCallback(false);
      }, 'afterClose');
      return function () {
        un1();
        un2();
      };
    }
  }, [openChangeCallback]);
  useEffect(function () {
    if (!innerRef.current.lockOpen && innerRef.current.tmpOpen !== undefined) {
      openChangeCallback(innerRef.current.tmpOpen, 'dropdown');
      innerRef.current.tmpOpen = undefined;
    }
  }, [openChangeCallback, state.options]);
  var newProps = _objectSpread(_objectSpread({
    allowClear: true
  }, others), {}, {
    showSearch: input,
    filterOption: false,
    ref: ref,
    placeholder: placeholder,
    disabled: disabled,
    optionLabelProp: 'label',
    style: _objectSpread({
      width: '100%',
      maxHeight: '100%'
    }, style),
    onChange: function onChange(value, opt) {
      if (_onChange) {
        if (value && opt && opt['data-origin']) {
          _onChange(_objectSpread({
            origin: opt['data-origin']
          }, value));
        } else {
          _onChange(value);
        }
      }
      if (multiple && newProps.maxTagCount === 'responsive') {
        // ant-design bug，响应式模式下，仅一项选择或取消时，焦点会丢失；（后期版本验证）
        Promise.resolve().then(function () {
          var _ref$current2, _ref$current2$focus;
          (_ref$current2 = ref.current) === null || _ref$current2 === void 0 || (_ref$current2 = _ref$current2.getApi()) === null || _ref$current2 === void 0 || (_ref$current2$focus = _ref$current2.focus) === null || _ref$current2$focus === void 0 || _ref$current2$focus.call(_ref$current2);
        });
      }
    },
    onDropdownVisibleChange: function onDropdownVisibleChange(open) {
      innerRef.current.open = open;
      _onDropdownVisibleChange === null || _onDropdownVisibleChange === void 0 || _onDropdownVisibleChange(open);
      if (!innerRef.current.lockOpen) {
        if (state.options.length > 0) {
          openChangeCallback(open, 'dropdown');
        } else {
          innerRef.current.tmpOpen = open;
        }
      }
    }
  });
  if (!buttonMode) {
    var loadData = /*#__PURE__*/function () {
      var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref11, delay) {
        var keyword,
          pageIndex,
          pageSize,
          check,
          query,
          _args7 = arguments;
        return _regeneratorRuntime().wrap(function _callee7$(_context7) {
          while (1) switch (_context7.prev = _context7.next) {
            case 0:
              keyword = _ref11.keyword, pageIndex = _ref11.pageIndex, pageSize = _ref11.pageSize;
              check = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : false;
              if (!(check && onBeforeOpen)) {
                _context7.next = 10;
                break;
              }
              setState(function (prevState) {
                return _objectSpread(_objectSpread({}, prevState), {}, {
                  loading: true
                });
              });
              _context7.next = 6;
              return onBeforeOpen(true);
            case 6:
              _context7.t0 = _context7.sent;
              if (!(_context7.t0 === false)) {
                _context7.next = 10;
                break;
              }
              setState(function (prevState) {
                return _objectSpread(_objectSpread({}, prevState), {}, {
                  loading: false
                });
              });
              return _context7.abrupt("return");
            case 10:
              innerRef.current.loaded = false;
              query = {
                keyword: keyword !== null && keyword !== void 0 ? keyword : state.query.keyword,
                pageIndex: pageIndex !== null && pageIndex !== void 0 ? pageIndex : state.query.pageIndex,
                pageSize: pageSize !== null && pageSize !== void 0 ? pageSize : state.query.pageSize,
                isInputSearch: true
              };
              setState(function (prevState) {
                return _objectSpread(_objectSpread({}, prevState), {}, {
                  loading: true,
                  firstLoad: false,
                  query: query
                });
              });
              fetch(function () {
                return dataRequest(query);
              }, function (options, total) {
                innerRef.current.loaded = true;
                setState(function (prevState) {
                  return _objectSpread(_objectSpread({}, prevState), {}, {
                    options: options,
                    loading: false,
                    total: total
                  });
                });
              }, delay);
            case 14:
            case "end":
              return _context7.stop();
          }
        }, _callee7);
      }));
      return function loadData(_x4, _x5) {
        return _ref12.apply(this, arguments);
      };
    }();
    if (onDoubleClick) {
      newProps.onDoubleClick = function (e) {
        onDoubleClick(e, ref.current);
      };
    }
    if (loadByFocus) {
      newProps.onFocus = /*#__PURE__*/function () {
        var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(e) {
          return _regeneratorRuntime().wrap(function _callee8$(_context8) {
            while (1) switch (_context8.prev = _context8.next) {
              case 0:
                if (state.firstLoad) {
                  loadData({
                    keyword: '',
                    pageIndex: 1
                  }, 0, true);
                }
              case 1:
              case "end":
                return _context8.stop();
            }
          }, _callee8);
        }));
        return function (_x6) {
          return _ref13.apply(this, arguments);
        };
      }();
    }
    if (input) {
      newProps.onSearch = function (keyword) {
        var inputValue = innerRef.current.lastInput;
        keyword = keyword.replace(/'/g, '');
        innerRef.current.lastInput = keyword;
        if (!keyword && !loadByFocus || !innerRef.current.open) {
          if (!keyword && acceptInput) {
            Promise.resolve().then(function () {
              var _ref$current3, _ref$current3$setValu;
              (_ref$current3 = ref.current) === null || _ref$current3 === void 0 || (_ref$current3 = _ref$current3.getApi()) === null || _ref$current3 === void 0 || (_ref$current3$setValu = _ref$current3.setValue) === null || _ref$current3$setValu === void 0 || _ref$current3$setValu.call(_ref$current3, {
                value: inputValue,
                label: inputValue
              });
            });
          }
          return;
        }
        loadData({
          keyword: keyword,
          pageIndex: 1
        }, 200, true);
      };
    }
    if (input || loadByFocus) {
      newProps.dropdownRender = function (menu) {
        return /*#__PURE__*/_jsx(DropdownRender, {
          pageChange: function pageChange(pageIndex, pageSize) {
            return loadData({
              pageIndex: pageIndex,
              pageSize: pageSize
            }, 0);
          },
          state: state,
          menu: menu
        });
      };
    }
    if (multiple) {
      newProps.mode = 'multiple';
      newProps.maxTagCount = newProps.hasOwnProperty('maxTagCount') ? newProps.maxTagCount : 'responsive';
      if (!tooltip) {
        newProps.maxTagPlaceholder = function (omittedValues) {
          var len = omittedValues === null || omittedValues === void 0 ? void 0 : omittedValues.length;
          if (len) {
            var tipTitle = /*#__PURE__*/_jsx("div", {
              style: {
                padding: '6px 8px',
                wordBreak: 'break-all',
                whiteSpace: 'normal'
              },
              onClick: function onClick(e) {
                return e.stopPropagation();
              },
              onMouseDown: function onMouseDown(e) {
                return e.stopPropagation();
              },
              children: omittedValues.map(function (v) {
                return v.label;
              }).join()
            });
            return /*#__PURE__*/_jsx(Tooltip, {
              overlayInnerStyle: {
                padding: 0
              },
              getTooltipContainer: function getTooltipContainer(target) {
                var _target$offsetParent;
                return ((_target$offsetParent = target.offsetParent) === null || _target$offsetParent === void 0 ? void 0 : _target$offsetParent.parentElement) || document.body;
              },
              title: tipTitle,
              mouseEnterDelay: 0.2,
              children: /*#__PURE__*/_jsxs("span", {
                style: {
                  display: 'inline-flex',
                  alignItems: 'center',
                  maxWidth: '100%'
                },
                children: [/*#__PURE__*/_jsx("span", {
                  className: "nowrap",
                  style: {
                    flex: 1
                  },
                  children: omittedValues[0].label
                }), len > 1 ? ",  + ".concat(len - 1, " ...") : ""]
              })
            });
          }
          return null;
        };
      }
    }
    if (newProps.maxTagCount === 'responsive') {
      newProps.className = iup.classNames(newProps.className, 'help-responsive');
    }
    if (!newProps.hasOwnProperty('popupMatchSelectWidth')) {
      newProps.popupMatchSelectWidth = false;
    }
    newProps.dropdownStyle = _objectSpread({
      maxWidth: '50vw'
    }, newProps.dropdownStyle);
    if (modal && !disabled) {
      if (!input) {
        newProps.onClick = function () {
          ref.current.openHelp();
        };
      } else {
        newProps.onDoubleClick = function (e) {
          if ((onDoubleClick === null || onDoubleClick === void 0 ? void 0 : onDoubleClick(e, ref.current)) !== false) {
            ref.current.openHelp();
          }
        };
      }
      newProps.suffixIcon = /*#__PURE__*/_jsx(OpenHelpIcon, {
        buttonMode: undefined,
        request: dataRequest,
        contentParams: _objectSpread(_objectSpread({}, props), contentParams),
        modalProps: modalProps,
        selectedRequest: selectedRequest,
        onBeforeOpen: onBeforeOpen,
        outRef: ref,
        helpContent: helpContent,
        style: iconStyle
      });
      newProps.className = 'help-with-icon';
    }
    var getDropColumns = function getDropColumns() {
      var _ref14 = (getHelpInfo === null || getHelpInfo === void 0 ? void 0 : getHelpInfo()) || {
          userCodeField: defaultUserCodeField,
          valueField: valueField,
          labelField: labelField
        },
        userCodeField = _ref14.userCodeField,
        vf = _ref14.valueField,
        lf = _ref14.labelField;
      var dropColumns = (userCodeField === null || userCodeField === void 0 ? void 0 : userCodeField.split(',').map(function (f) {
        var _f$trim$split = f.trim().split(':'),
          _f$trim$split2 = _slicedToArray(_f$trim$split, 2),
          key = _f$trim$split2[0],
          width = _f$trim$split2[1];
        return {
          dataIndex: key,
          width: width
        };
      })) || [{
        dataIndex: vf
      }, {
        dataIndex: lf
      }];
      if (userCodeFieldWithLabel && !dropColumns.find(function (_ref15) {
        var dataIndex = _ref15.dataIndex;
        return dataIndex === lf;
      })) {
        dropColumns.push({
          dataIndex: lf
        });
      }
      return dropColumns;
    };
    newProps.tooltip = tooltip;
    newProps.notFoundContent = state.loading ? /*#__PURE__*/_jsx("div", {
      style: {
        minHeight: 28
      }
    }) : loadByFocus && innerRef.current.loaded ? /*#__PURE__*/_jsx(Empty, {
      image: Empty.PRESENTED_IMAGE_SIMPLE
    }) : null;
    if (isTree) {
      delete newProps.filterOption;
      delete newProps.popupMatchSelectWidth;
      delete newProps.mode;
      newProps.multiple = multiple;
      newProps.filterTreeNode = false;
      var treeData = iup.deepCopy(state.options);
      iup.loopChildren({
        children: treeData
      }, function (d) {
        var _ref16 = [getValue(d), getValue(d, 'label')],
          value = _ref16[0],
          label = _ref16[1];
        d.value = value;
        d.label = label;
        d.key = value;
      });
      return /*#__PURE__*/_jsx(Select, _objectSpread(_objectSpread({
        defaultOpen: newProps.autoFocus && loadByFocus,
        isTree: true
      }, newProps), {}, {
        data: treeData
      }));
    }
    return /*#__PURE__*/_jsx(Select, _objectSpread(_objectSpread({}, newProps), {}, {
      children: state.options.map(function (d) {
        var _ref17 = [getValue(d), getValue(d, 'label')],
          value = _ref17[0],
          label = _ref17[1];
        var _ref18 = nowrap ? [label, 'nowrap', 'nowrap'] : ['', '', 'normal'],
          _ref19 = _slicedToArray(_ref18, 3),
          title = _ref19[0],
          cls = _ref19[1],
          whiteSpace = _ref19[2];
        return /*#__PURE__*/_jsx(Select.Option, {
          value: value,
          label: label,
          "data-origin": d.origin || d,
          children: /*#__PURE__*/_jsx("div", {
            style: {
              display: 'flex',
              alignItems: 'center',
              minHeight: 22
            },
            title: title,
            children: getDropColumns().map(function (_ref20, index) {
              var c = _ref20.dataIndex,
                width = _ref20.width;
              var s = {
                  flex: 1
                },
                key = c,
                content = '';
              if (iup.isFunction(c)) {
                key = index;
                content = c(d);
              } else {
                var _d$c;
                s = width ? {
                  width: width
                } : s;
                content = (_d$c = d[c]) !== null && _d$c !== void 0 ? _d$c : content;
              }
              return /*#__PURE__*/_jsx("div", {
                className: cls,
                style: _objectSpread(_objectSpread({}, s), {}, {
                  marginRight: 5,
                  whiteSpace: whiteSpace,
                  wordBreak: 'break-all',
                  lineHeight: 1
                }),
                children: content
              }, key);
            })
          })
        }, value);
      })
    }));
  }
  return /*#__PURE__*/_jsx(OpenHelpIcon, {
    buttonMode: buttonMode,
    request: dataRequest,
    contentParams: _objectSpread(_objectSpread({}, props), contentParams),
    modalProps: modalProps,
    selectedRequest: selectedRequest,
    onBeforeOpen: onBeforeOpen,
    outRef: ref,
    helpContent: helpContent,
    style: iconStyle
  });
};
BaseHelp.Header = Header;
BaseHelp.Footer = Footer;
BaseHelp.MultipleButtons = MultipleButtons;
export { HelpContext };
function Help(_ref21) {
  var _ref21$type = _ref21.type,
    type = _ref21$type === void 0 ? 'MultipleHelp' : _ref21$type,
    closeReturn = _ref21.closeReturn,
    props = _objectWithoutProperties(_ref21, _excluded3);
  var _getRegisterComponent = getRegisterComponentWithProps(type),
    _getRegisterComponent2 = _slicedToArray(_getRegisterComponent, 2),
    Tmp = _getRegisterComponent2[0],
    defaultProps = _getRegisterComponent2[1];
  var tmpRef = useRef();
  useEffect(function () {
    var _api$openHelp;
    var api = tmpRef.current.getApi();
    (_api$openHelp = api.openHelp) === null || _api$openHelp === void 0 || _api$openHelp.call(api);
    return api.getHelper().observer.subscribe(function (param) {
      closeReturn(param || {});
    }, 'afterClose');
  }, []);
  return /*#__PURE__*/_jsx(Tmp, _objectSpread(_objectSpread(_objectSpread({}, defaultProps), props), {}, {
    ref: tmpRef,
    style: {
      display: 'none',
      width: 0,
      height: 0
    }
  }));
}
function openHelp(config) {
  return new Promise(function (resolve) {
    var div = document.createElement('div');
    document.body.appendChild(div);
    var root = createRoot(div);
    var helpProps = _objectSpread(_objectSpread({}, config), {}, {
      closeReturn: function closeReturn(_ref22) {
        var result = _ref22.result;
        resolve(result);
      },
      modalProps: _objectSpread(_objectSpread({}, config.modalProps), {}, {
        afterClose: function afterClose() {
          setTimeout(function () {
            root.unmount();
            if (div.parentNode) {
              div.parentNode.removeChild(div);
            }
          });
        }
      })
    });
    root.render( /*#__PURE__*/_jsx(Help, _objectSpread({}, helpProps)));
  });
}
iup.registerExternal({
  openHelp: openHelp
});